
import numpy as np
import cv2 as cv

# 创建8*8照片
img = np.full((8, 8, 3), [255,255,255] , dtype=np.uint8)
cv.line(img, (0,0), (7,7), (255,0,0), 1)    # 画直线, 做平移标记
cv.imshow('1_orgin_img',img)
# cv.waitKey(0)

# 平移图像
(h,w) = img.shape[:2]
M = np.float32([[1, 0, 4], [0, 1, 2]]) # 向右平移4个像素，向下平移2个像素
translated_img = cv.warpAffine(img, M, (w,h))
cv.imshow('2_translated_img',translated_img)
cv.waitKey(0)

cv.destroyAllWindows()